import React, { useState, useEffect } from "react"
import useStore from "../context/useStore"
import "./index/My.scss"
const Login: React.FC = () => {

    const [pop, setPop] = useState<string>("")
    const [code, setCode] = useState<string>("")
    let { mine } = useStore()
    useEffect(() => {
        mine.getUserInfo()
    }, [mine])
    function sendCode() {
        if (!(/^1[3456789]d{9}$/.test(pop))) {
            mine.sendCode(pop)
        }
    }
    function goLogin() {
        mine.changeMobile(pop).then(res => {
            console.log(res)
        })
    }
    return <div className="Login">
        <div className="log">
            <div><input type="number" placeholder="请输入手机号" value={pop} onChange={el => setPop(el.target.value)} /></div>
            <div><input type="number" maxLength={6} placeholder="请输入验证码" value={code} onChange={el => setCode(el.target.value)} /><span onClick={sendCode}>获取验证码</span></div>
        </div>
        <div>
            <button onClick={goLogin}>修改手机号</button>
        </div>
    </div>
}

export default Login